package cn.appsys.controller.backend;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.appsys.pojo.BackendUser;
import cn.appsys.service.backend.BackendUserService;
import cn.appsys.tools.Constants;

@Controller
@RequestMapping(value="/manager")
public class BackendLoginController {
	
	@Resource
	BackendUserService backendUserService;
	
	@RequestMapping(value="index")
	public String index(){
		return "index";
	}
	
	@RequestMapping(value="/login")
	public String login(){
		return "backendlogin";
	}
	
	@RequestMapping(value="/dologin")
	public String userdoLogin(HttpSession session,@RequestParam(value="userCode") String userCode,@RequestParam(value="userPassword")String userPassword){
		BackendUser manager=null;
		try {
			manager=backendUserService.login(userCode, userPassword);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(null!=manager){
			session.setAttribute(Constants.USER_SESSION, manager);
			return "/backend/main";
		}else{
			return "backendlogin";
		}
		
	}
}
